module test_point_mod

use pFUnit

use test_base_mod

use point_mod

!> Overload the pFUnit assert for points
interface assertEqual
    module procedure assertEqual_ptObj
end interface

contains

subroutine Run_Point_Tests()
    type(TestSuite_type)  :: suite
    type(TestResult_type) :: result
    character(len=100) :: summary_statement

    ! Build suite from test procedures:
    suite = TestSuite( 'Test point_mod' )
    call add ( suite, TestCase1Step ( 'Test_Point_Create',   Test_Point_Create   ) )
    call add ( suite, TestCase1Step ( 'Test_Point_Distance', Test_Point_Distance ) )
!    call add ( suite, TestCase1Step ( 'test_buildaxis',    test_buildaxis    ) )
!    call add ( suite, TestCase1Step ( 'test_fileinitvtk',  test_fileinitvtk  ) )
    result = newTestResult ( mode=MODE_USE_STDOUT )

    call Run('point_mod', suite, result)

    call clean( result )
    call clean( suite )
end subroutine Run_Point_Tests

!> Check the point creation function works
subroutine Test_Point_Create()
    type(PointObj) :: pt
    pt = Point(1.0, 2.0, 3.0)
    call assertEqual(1.0, 2.0, 3.0, pt, "Point position")
end subroutine Test_Point_Create

!> Check that the distance between two points is computed correctly
subroutine Test_Point_Distance()
    type(PointObj) :: pt1, pt2
    real :: d
    pt1 = Point(0.0, 0.0, 0.0)
    pt2 = Point(1.0, 2.0, 3.0)
    d = Point_Distance(pt1, pt2)
    call assertEqual(sqrt(14.0), d, "Distance between points - increasing")
    d = Point_Distance(pt2, pt1)
    call assertEqual(sqrt(14.0), d, "Distance between points - decreasing")
end subroutine Test_Point_Distance

!> overload routine for pfUnit assert for PointObj
subroutine assertEqual_ptobj(x, y, z, pt_in, mesg)
    real,             intent(in) :: x
    real,             intent(in) :: y
    real,             intent(in) :: z
    type(PointObj),   intent(in) :: pt_in
    character(len=*), optional   :: mesg
    call assertEqual(x, pt_in%x, mesg)
    call assertEqual(y, pt_in%y, mesg)
    call assertEqual(z, pt_in%z, mesg)
end subroutine assertEqual_ptobj


end module test_point_mod
